//将四个人的信息读到一个结构体数组里，并输出该结构体数组
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct STU
{
    char name[20];
    int age;
    float score;
}STU;

int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("参数有误\n");
        return 0;
    }
    else
    {
        FILE *file=fopen(argv[1],"r");
        if(file == NULL)
        {
            printf("error\n");
            return 0;
        }
        else
        {
            //printf("ok1\n");
            int i=0;
            STU stu[4]={'\0'};
            for(i=0;i<4;i++)
            {
                int j=0;
                int k=0;
                char score[20]={'\0'};
                while(1)
                {
                    char ch='\0';
                    //fseek(file,1,SEEK_CUR);
                    ch=fgetc(file);
                    if(ch == '#')
                    {
                        //printf("ok2\n");
                        //printf("%s \n",stu[i].name);
                        break;
                    }
                    stu[i].name[j]=ch;
                    j++;
                    //strcat(stu[i].name,&ch);
                }
                while(1)
                {
                    char ch='\0';
                    //fseek(file,1,SEEK_CUR);
                    ch=fgetc(file);
                    if(ch == '#')
                    {
                        //printf("%d\n",stu[i].age);
                        //printf("ok3\n");
                        break;
                    }
                    stu[i].age=10*stu[i].age+(ch-'0');
                }
                while(1)
                {
                    char ch='\0';
                    //fseek(file,1,SEEK_CUR);
                    ch=fgetc(file);
                    if(ch == '\n')
                    {
                        //printf("%s\n",score);
                        stu[i].score=atof(score);
                        //printf("ok4\n");
                        break;
                    }
                    score[k]=ch;
                    k++;
                    //strcat(score,&ch);
                }
            }
            printf("name\t \tage\tscore\n");
            for(i=0;i<4;i++)
            {
                printf("%s\t \t%d\t%g\n",stu[i].name,stu[i].age,stu[i].score);
            }
        }
        
    }
    return 0;
}